﻿##此DEMO的功能：查询手机类的淘客商品
# -*- coding: utf-8 -*-
import urllib, urllib2, string, time, md5, re, types, logging

#获得当前时间
t = time.localtime()

#参数数组
paramArray = {
	'app_key':'12022540',
	'method':'taobao.taobaoke.listurl.get',
	'format':'json',
	'v':'2.0',
	'timestamp':time.strftime('%Y-%m-%d %X', t),

	'q':'三星',
  'nick':'xiaojay2006',
  'outer_code':'123456'
}

#签名函数
def _sign(param,sercetCode):
	src = sercetCode + ''.join(["%s%s" % (k, v) for k, v in sorted(param.items())])
	return md5.new(src).hexdigest().upper()
	

#生成签名
sign = _sign(paramArray, '6f7a04f813d9a9fc916e0b15854e9f6f')
paramArray['sign'] = sign

#组装参数
form_data = urllib.urlencode(paramArray)

#访问服务
urlopen = urllib2.urlopen('http://gw.api.taobao.com/router/rest', form_data)

rsp = urlopen.read()
rsp = rsp.decode('UTF-8')
print rsp
'''
import simplejson as json

rsp = json.loads(rsp)
data = rsp['taobaoke_items_get_response']
total = data['total_results']
items = data['taobaoke_items']['taobaoke_item']
i = items[0]
'''
